package com.site.controller.manage;

import com.site.model.Info;
import com.site.service.InfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by robin on 2016/12/14.
 * 信息controller
 */
@Controller
@RequestMapping("manage/info")
public class InfoController {
    @Autowired
    private InfoService service;

    @RequestMapping("release")
    public String release(Model model){
        return "manage/info/release";
    }

    @RequestMapping("main")
    public String main(Model model){
        return "manage/info/main";
    }

    @RequestMapping("search")
    public String search(Model model,String startDate,String endDate, String cate,String key,
                         int pageNum,@RequestParam(defaultValue = "5")int pageSize,
                         @RequestParam(defaultValue = "")String title,@RequestParam(defaultValue = "")String proSer){
        Map param = new HashMap();
        param.put("startDate",startDate);param.put("endDate",endDate);
        param.put("cate",cate);param.put("key",key);
        model.addAttribute("data",service.search(param,pageNum,pageSize));
        model.addAttribute("title",title);
        model.addAttribute("proSer",proSer);
        return "manage/info/search";
    }

    @RequestMapping("editPage")
    public String editPage(Model model,String id){
        model.addAttribute("data",service.selectById(id));
        return "manage/info/edit";
    }

    @RequestMapping("save")
    @ResponseBody
    public int save(Info info){
        return service.save(info);
    }

    @RequestMapping("upSort")
    @ResponseBody
    public int upSort(String id,Integer sort){
        return service.upSort(id,sort);
    }

    @RequestMapping("downSort")
    @ResponseBody
    public int downSort(String id,Integer sort){
        return service.downSort(id,sort);
    }

    @RequestMapping("del")
    @ResponseBody
    public int del(String id){
        return service.delete(id);
    }

    @RequestMapping("delAll")
    @ResponseBody
    public int delAll(String ids){
        return service.deleteAll(ids);
    }

    @RequestMapping("edit")
    @ResponseBody
    public int edit(Info info){
        return service.edit(info);
    }
}
